package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.JTextArea;
import java.awt.Insets;

public class TourGUI extends JFrame {

	private JPanel contentPane;
	private JTextArea textArea;
	private String[] artifactInfo;
	private String[] tour;
	
	/**
	 * Create the frame.
	 * @param tour 
	 */
	public TourGUI(String[] tour, String[] artifactInfo, String title) {
		super(title);
		this.tour = tour;
		this.artifactInfo = artifactInfo;
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JList artifactList = new JList();
		artifactList.setModel(new AbstractListModel() {
			String[] values = TourGUI.this.tour;
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});
		artifactList.addListSelectionListener(new ListSelectionListener(){
			@Override
			public void valueChanged(ListSelectionEvent e) {
				updateInfo(((JList)e.getSource()).getSelectedIndex());
			}
		});
		
		JScrollPane scrollPane = new JScrollPane(artifactList);
		contentPane.add(scrollPane, BorderLayout.WEST);
		
		textArea = new JTextArea();
		textArea.setMargin(new Insets(5, 10, 5, 5));
		textArea.setEditable(false);
		textArea.setBackground(new Color(238,238,238));
		contentPane.add(textArea, BorderLayout.CENTER);
	}
	
	private void updateInfo(int index) {
		textArea.setText(artifactInfo[index]);
	}

}
